package com.example.usharingtest.service;

import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.usharingtest.R;
import com.example.usharingtest.adapter.postAdapter;
import com.example.usharingtest.model.Article;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * Created by X on 2017/9/8.
 */
public class ArticleURL {
    String result = "";

    public String postArticleURL(String URL, RequestParams params){
            AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

            asyncHttpClient.setTimeout(11000);   //设置链接超时，如果不设置，默认为10s

            asyncHttpClient.get(URL,params, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(String content) {
                    Log.d("内容", content);
                    JSONObject jsonObject = JSONObject.parseObject(content);
                    boolean success = jsonObject.getBoolean("success");
                    if (success) {
                        result = jsonObject.getString("data");
                        Log.d("strobj", result);
                    }else{
                        result = "dbfailed";
                    }
                }
                @Override
                public void onFailure(Throwable error, String content) {
                    result = "failed";
                }
            });
        return result;
    }
}
